package com.dpp.mapper;

import com.dpp.entity.AddressBook;
import com.dpp.entity.Withdraw;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressMapper {


    @Insert("INSERT INTO address_book(address, is_default, openid, phone) VALUES (#{address}, #{isDefault}, #{openid}, #{phone})")
    void save(AddressBook addressBook);

    @Select("select * from address_book where address = #{address} and openid = #{openid} and phone = #{phone}")
    AddressBook selectByIdAndAddressAndUserIdAndPhone(String address, String openid,String phone);

    @Select("select * from address_book where address = #{address} and openid = #{openid} and phone = #{phone}")
    AddressBook selectByAddressAndUserIdAndPhone(String address, String openid,String phone);
    @Update("update address_book set address = #{address},phone = #{phone},is_default = #{isDefault} where id = #{id}")
    void updateAddress( Integer id,String phone,String address,Integer isDefault);

    @Delete("DELETE FROM address_book WHERE id = #{id}")
    void deleteAddress(Integer id);


    @Select("select * from address_book where openid = #{openid}")
    List<AddressBook> selectAllAddress(String openid);


    @Update("update address_book set is_default=0 where openid = #{openid}")
    void clearDA(String openid);

    @Update("update address_book set is_default = #{isDefault} where id = #{id}")
    void updateDA(AddressBook addressBook);

    @Select("select t2.* from users t1,address_book t2 where t1.openid = #{openId} and t1.openid = t2.openid and t2.phone=#{phone} and t2.address=#{address}")
    AddressBook selectByOpenidAndPhoneAndAddress(String openId, String phone, String address);

    @Select("select t2.* from users t1,address_book t2 where t1.openid = #{openid} and t1.openid = t2.openid and t2.is_default = 1")
    AddressBook selectByOpenid(String openid);

    @Select("select * from address_book where id=#{id}")
    AddressBook selectById(int id);

}
